package com.example.jh352160.surfingtv.commodity_details.customView;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.example.jh352160.surfingtv.R;

/**
 * Created by jh352160 on 2016/7/29
 */

public class Share_page extends RelativeLayout {

    Context context;
    ImageView back, qq, weixin, weibo, friendCircle;
    View share_page;

    public Share_page(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.context = context;
        init();
    }

    public Share_page(Context context) {
        super(context);
        this.context = context;
        init();
    }

    private void init() {
        LayoutInflater.from(context).inflate(R.layout.commodity_share_button, this);
        back = (ImageView) findViewById(R.id.back);
        qq = (ImageView) findViewById(R.id.qq);
        weixin = (ImageView) findViewById(R.id.weixin);
        weibo = (ImageView) findViewById(R.id.weibo);
        share_page = findViewById(R.id.share_view);
        friendCircle = (ImageView) findViewById(R.id.friendCircle);

        share_page.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                stopAnim();
            }
        });
    }

    public void startAnim() {
        Animation animation1 = new TranslateAnimation(0, 0, -500, 0);
        animation1.setDuration(100);
        Animation animation2 = new TranslateAnimation(140, 0, -350, 0);
        animation2.setDuration(100);
        Animation animation3 = new TranslateAnimation(350, 0, -140, 0);
        animation3.setDuration(100);
        Animation animation4 = new TranslateAnimation(500, 0, 0, 0);
        animation4.setDuration(100);
//        Animation anim1= AnimationUtils.loadAnimation(context,R.anim.share1);
//        Animation anim2= AnimationUtils.loadAnimation(context,R.anim.share2);
//        Animation anim3= AnimationUtils.loadAnimation(context,R.anim.share3);
//        Animation anim4= AnimationUtils.loadAnimation(context,R.anim.share4);
        weibo.startAnimation(animation1);
        weixin.startAnimation(animation2);
        friendCircle.startAnimation(animation3);
        qq.startAnimation(animation4);
    }

    public void stopAnim() {
        Animation animation1 = new TranslateAnimation(0, 0, 0, -500);
        animation1.setDuration(100);
        Animation animation2 = new TranslateAnimation(0, 140, 0, -350);
        animation2.setDuration(100);
        Animation animation3 = new TranslateAnimation(0, 350, 0, -1400);
        animation3.setDuration(100);
        Animation animation4 = new TranslateAnimation(0, 500, 0, 0);
        animation4.setDuration(100);
//        Animation anim1= AnimationUtils.loadAnimation(context,R.anim.share_back1);
//        Animation anim2= AnimationUtils.loadAnimation(context,R.anim.share_back2);
//        Animation anim3= AnimationUtils.loadAnimation(context,R.anim.share_back3);
//        Animation anim4= AnimationUtils.loadAnimation(context,R.anim.share_back4);
        weibo.startAnimation(animation1);
        weixin.startAnimation(animation2);
        friendCircle.startAnimation(animation3);
        qq.startAnimation(animation4);
        animation1.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

            }

            @Override
            public void onAnimationEnd(Animation animation) {
                Share_page.this.setVisibility(GONE);
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }
}
